# Monarc makefile

CC  = gcc
AS  = nasm
LD  = ld
AR  = ar
SED = sed
PL = perl

INCL = \
	-I../libc/include \
	-I../libsys/include \
	-Iinclude \
	-Iinclude/c_compatibility \

DEFINES = \
	-DMONARC \
	-D_MONARC=1 \
	-DATTRIBUTE_UNUSED= \
	-DTARGET_ATTRIBUTE_WEAK= \
	-Dinhibit_libc \
	-DCRT_BEGIN \
	-DINIT_SECTION_ASM_OP \
	-DEH_FRAME_SECTION_NAME=\".eh_frame\" \
#	-D__DEBUG \
	
OPT_OR_DEBUG = \
	-O
	
C_OPT = -Wall $(OPT_OR_DEBUG) -ffreestanding -nostartfiles -nodefaultlibs -nostdlib -nostdinc $(INCL) $(DEFINES)
OC_OPT = -Wall $(OPT_OR_DEBUG) -ffreestanding -nostartfiles -nodefaultlibs -nostdlib -nostdinc $(INCL) $(DEFINES)

CC_OPT = -Wall $(OPT_OR_DEBUG) -nostartfiles -fno-builtin -nodefaultlibs -nostdlib -nostdinc $(INCL) $(DEFINES)
OCC_OPT = -Wall $(OPT_OR_DEBUG) -nostartfiles -fno-builtin -nodefaultlibs -nostdlib -nostdinc $(INCL) $(DEFINES)

MKDIR = mkdir
CP = cp
CAT = cat
RM = rm -f

c_sources = \
	unwind-c.c \
	unwind-dw2-fde-darwin.c \
	unwind-dw2-fde-glibc.c \
	unwind-dw2-fde.c \
	unwind-dw2.c \
	unwind-libunwind.c \
	unwind-sjlj.c \
#	crtstuff.c \
#	cxa_demangle.c \
#	dyn-string.c \


sources = \
	eh_alloc.cc \
	eh_aux_runtime.cc \
	eh_catch.cc \
	eh_exception.cc \
	eh_globals.cc \
	eh_personality.cc \
	eh_terminate.cc \
	eh_throw.cc \
	eh_type.cc \
	guard.cc \
	new_handler.cc \
	pure.cc \
	tinfo.cc \
	tinfo2.cc \
	vec.cc \
	new_op.cc \
	new_opnt.cc \
	new_opv.cc \
	new_opvnt.cc \
	del_op.cc \
	del_opnt.cc \
	del_opv.cc \
	del_opvnt.cc \
	

	

all: libsupc++.a

clean:
	$(RM) *.o libsupc++.a

libsupc++.a: $(sources:.cc=.o) $(c_sources:.c=.o)
	ar cru $@ $?

%.o : %.asm
	$(REDIR) $(AS) -fwin32 $< -o $@

%.o: %.c
	$(REDIR) $(CC) $(OC_OPT) -c $< -o $@

%.o: %.cc
	$(REDIR) $(CC) $(OCC_OPT) -c $< -o $@

